package com.koron.ticket.workchange.ticketchangeinterrupt.service.impl;


import com.koron.bean.base.Response;
import com.koron.common.core.util.CodeTools;
import com.koron.ticket.workchange.ticketchangeinterrupt.bean.TicketChangeInterrupt;
import com.koron.ticket.workchange.ticketchangeinterrupt.bean.TicketChangeInterruptQuery;
import com.koron.ticket.workchange.ticketchangeinterrupt.mapper.TicketChangeInterruptMapper;
import com.koron.ticket.workchange.ticketchangeinterrupt.service.TicketChangeInterruptService;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (TicketChangeInterrupt)表服务实现类
 *
 * @author 朱超
 * @since 2021-10-27 09:54:10
 */
@Service
public class TicketChangeInterruptServiceImpl implements TicketChangeInterruptService {

    /**
     * 新增数据
     *
     */
    @Override
    @TaskAnnotation("insert")
    public Response insert(SessionFactory factory, TicketChangeInterrupt ticketChangeInterrupt) {
        TicketChangeInterruptMapper mapper = factory.getMapper(TicketChangeInterruptMapper.class);
        String id = CodeTools.getCode32();
        ticketChangeInterrupt.setId(id);
        mapper.insert(ticketChangeInterrupt);
        return Response.success(id);
    }

    /**
     * 根据id删除单条数据
     *
     */
    @Override
    @TaskAnnotation("deleteById")
    public Response deleteById(SessionFactory factory, String id) {
        TicketChangeInterruptMapper mapper = factory.getMapper(TicketChangeInterruptMapper.class);
        mapper.deleteById(id);
        return Response.success("删除成功");
    }

    /**
     * 根据workTicketId删除相关数据
     *
     */
    @Override
    public void deleteByWorkTicketId(SessionFactory factory, String workTicketId) {
        TicketChangeInterruptMapper mapper = factory.getMapper(TicketChangeInterruptMapper.class);
        mapper.deleteByWorkTicketId(workTicketId);
    }

    /**
     * 更新数据
     *
     */
    @Override
    @TaskAnnotation("update")
    public Response update(SessionFactory factory, TicketChangeInterrupt ticketChangeInterrupt) {
        TicketChangeInterruptMapper mapper = factory.getMapper(TicketChangeInterruptMapper.class);
        mapper.update(ticketChangeInterrupt);
        return Response.success("更新成功");
    }

    /**
     * 根据id查询单条数据
     *
     */
    @Override
    @TaskAnnotation("getById")
    public Response getById(SessionFactory factory, String id) {
        TicketChangeInterruptMapper mapper = factory.getMapper(TicketChangeInterruptMapper.class);
        TicketChangeInterruptQuery query = new TicketChangeInterruptQuery();
        query.setId(id);
        TicketChangeInterrupt ticketChangeInterrupt = mapper.getSingle(query);
        return Response.success(ticketChangeInterrupt);
    }

    @Override
    public TicketChangeInterrupt getSingle(SessionFactory factory, TicketChangeInterruptQuery ticketChangeInterruptQuery) {
        TicketChangeInterruptMapper mapper = factory.getMapper(TicketChangeInterruptMapper.class);
        return mapper.getSingle(ticketChangeInterruptQuery);
    }

    @Override
    public List<TicketChangeInterrupt> getList(SessionFactory factory, TicketChangeInterruptQuery ticketChangeInterruptQuery) {
        TicketChangeInterruptMapper mapper = factory.getMapper(TicketChangeInterruptMapper.class);
        return mapper.getList(ticketChangeInterruptQuery);
    }

}
